package src.edu.wayne.cs.csc4110.hw6.implementations.userPanels;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import src.edu.wayne.cs.csc4110.hw6.implementations.VideoFrameImpl;
import src.edu.wayne.cs.csc4110.hw6.implementations.stateMachine.StateMachine;
import src.edu.wayne.cs.csc4110.hw6.interfaces.State;



public class UserHomePanel extends StateMachinePanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1681547309611900119L;
	
	public UserHomePanel(StateMachine stateMachine){
		super(stateMachine);
	
		//Create a panel
		this.setLayout(new BorderLayout(0, 175));
		this.setBackground(VideoFrameImpl.getColor());
		this.setForeground(VideoFrameImpl.getColor());
		this.add(new JLabel("This page needs some work"), BorderLayout.NORTH);
		
		
		//Put buttons on it
		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new GridLayout(1,0));
		buttonPanel.setBackground(VideoFrameImpl.getColor());
		
		
		JPanel centerPanel = new JPanel();
		centerPanel.setLayout(new GridLayout(0,1,2,2));
		centerPanel.setBackground(VideoFrameImpl.getColor());
		centerPanel.add( new JTextField("The games should show up here.") );	

		
		this.add(centerPanel, BorderLayout.CENTER);
		

		buttonPanel.add(new JButton("place holder"));
		buttonPanel.add(getAddUserButton());
		buttonPanel.add(getLogOutButton());
		
		this.add(buttonPanel, BorderLayout.SOUTH);
		
		String titleString = new String("Home Panel:  ");
		titleString = titleString.concat(stateMachine.getCurrentUser().getFullname());
		stateMachine.setDisplayPanel(this, titleString);
	}

	
	private JButton getAddUserButton()
	{
		JButton jbtnAddUser = new JButton("Login Another user");
		jbtnAddUser.addActionListener(
				new ActionListener() 
				{
					public void actionPerformed(ActionEvent e)
					{
						goToLoginState();
					}
				}
			);
		return jbtnAddUser;
	}
	
	private JButton getLogOutButton()
	{
		JButton jbtnAddUser = new JButton("Log Current User Out");
		jbtnAddUser.addActionListener(
				new ActionListener() 
				{
					public void actionPerformed(ActionEvent e)
					{
						logOutCurrentUser();
					}
				}
			);
		return jbtnAddUser;
	}

	public void goToLoginState(){
		stateMachine.setState(stateMachine.getNotLoggedInState());
		stateMachine.goToLoggedInState();
	}
	
	public void logOutCurrentUser(){
		stateMachine.logOutCurrentUser();
	}
}